$(document).ready(function() {

	initWebUploader();
});


function initWebUploader() {
	var uploader = WebUploader.create({
          server: '#',
          pick: {
            "id":'#selectImg',   
            "multiple":false   //禁止多选。     
          },  
          auto: true,
          //分片上传设置
          chunked:true,  //允许分片
          chunkSize:2*1024*1024, //每片大小2M
          chunkRetry:4,  //分片上传失败之后的重试次数
          threads:3,  //上传并发数。允许同时最大3个上传进程
          duplicate:true,

          //上传文件个数限制
          fileNumLimit:1,
          //单个文件大小限制  20M
          fileSingleSizeLimit:20*1024*1024,
          accept: {
            title: 'Images',
            extensions: 'gif,jpg,jpeg,bmp,png',
            mimeTypes: 'image/*'
          },  
          thumb: {
              width: 200,
              height: 200,
              quality: 100,
              allowMagnify: false,
              crop: true,
              type: 'image/jpeg'
          } ,             
      });

      uploader.on( 'fileQueued', function( file ) {
    
              uploader.makeThumb( file, function( error, ret ) {
                $("#selectImgDiv").empty();
                     if ( error ) {
                      $("#selectImgDiv").append('<label>预览错误</label>');
                     } else {
                          $("#selectImgDiv").append('<img alt="" src="' + ret + '" />');
                     }
              });
      });

       uploader.on( 'uploadComplete', function( file ) {
                console.log("uploadComplete");
                uploader.reset();
       });
      uploader.on( 'uploadSuccess', function( file ) {
                console.log("uploadSuccess");
       });
       uploader.on( 'uploadError', function( file ) {
                console.log("uploadError");
       });
}

